<?php

namespace UI;

class Tag {

	public static function icon($icon = '', $atts = array ()) {
		return static::btn('<span class="ico-' . $icon . '"></span>', $atts);
	}

	public static function btn_add($url = '', $disabled = false) {
		return static::btn('Add new', array('href' => \Uri::create($url)), $disabled);
	}

	public static function btn_del($url = '', $disabled = false) {
		return static::btn('Delete', array('href' => \Uri::create($url)), $disabled);
	}

	public static function btn_cancel($url = '', $disabled = false) {
		return static::btn('Cancel', array('href' => \Uri::create($url)), $disabled);
	}

	public static function btn_edit($url = '', $disabled = false) {
		return static::btn('Edit', array('href' => \Uri::create($url)), $disabled);
	}

	public static function btn_icon($icon = '', $url = '', $disabled = false) {
		return static::btn('<span class="ico-' . $icon . '"></span>', array('href' => \Uri::create($url)), $disabled);
	}

	public static function btn($title = '', $atts = array (), $disabled = false) {
		if ($title == '')
			return '';
		$html = '<a class="btn' . ($disabled ? ' btn-disabled' : '') . '"';

		$atts_html = ' ';
		if (is_array($atts)) {
			$atts_html .= array_to_attr($atts);
		}
		$html .= $atts_html . '>' . $title . '</a>';

		return $html;
	}

	public static function multiple_select($name = 'multiple_select', $value = null, $items = array(), $options = array()) {
		$id = isset($options['id']) ? $options['id'] : uniqid();
		$out = \Form::select($name, $value, $items, array(
			'id' => $id,
			'class' => 'not-uniform',
			'multiple' => 'multiple'
		));
		$out .= "<script type=\"text/javascript\">
					(function($){
						$('#{$id}').multiSelect({
							keepOrder: true
						});
					})(jQuery);
				</script>";
		return $out;
	}

}
